import {
	NavigationActions
} from 'react-navigation';

let _navigator;

const setTopLevelNavigator = (navigatorRef) => {
	_navigator = navigatorRef;
}

const navigate = (routeName, params) => {
	_navigator.props.dispatch(
		NavigationActions.navigate({
			routeName,
			params,
		})
	);
}

const logout = (routeName, params) => {
	_navigator.props.dispatch(
		NavigationActions.reset({
			index: 0,
			actions: [
				NavigationActions.navigate({
					routeName,
					params
				})
			]
		})
	);
}

export default {
	navigate,
	logout,
	setTopLevelNavigator,
};